<?php 
class DefaultModule
{
	function index() {
		global $_G;
		$cates = $_G['cache']->get('category');
		
		include template('index');
		exit;
		$primary_links = $this->get_menu();
		$recommend = $this->get_recommend(8);
		$new = $this->get_newgoods(8);
		$categorys = $this->get_categorys();
	}
	function get_menu($type='primary') {
		global $_G;
		$menus = $_G['cache']->get('primary_menu') ;
		if(!$menus) {
			$menu = array();
			$datas = $_G['db']->fetch('menus','*', array('type' => $type),"weight ASC");
			if(is_array($datas)) {
			    foreach($datas as $data) {
					$menu[$data['parentid']][$data['mid']] = $data;
				}
			}
			$menus = tree($menu);
			$_G['cache']->set('primary_menu',$menus) ;
		}
		return $menus;
	}
	function get_recommend($num=10) {
		global $_G;
		$recommend = $_G['cache']->get('index_recommend_goods') ;
		if(!$recommend) {
			$query = $_G['db']->query("SELECT * FROM ".DB_PREFIX."product WHERE recommend=1 AND status=1 ORDER BY pid DESC limit ".$num);
			while($data = $_G['db']->fetch_array($query)){
				$recommend[$data['pid']] = $data;
			}
			$_G['cache']->set('index_recommend_goods',$recommend);
		}
		return $recommend;
	}
	function get_newgoods($num=10) {
		global $_G;
		$newgoods = $_G['cache']->get('index_new_goods') ;
		if(!$newgoods) {
			$query = $_G['db']->query("SELECT * FROM ".DB_PREFIX."product WHERE status=1 ORDER BY pid DESC limit ".$num);
			while($data = $_G['db']->fetch_array($query)){
				$newgoods[$data['pid']] = $data;
			}
			$_G['cache']->set('index_new_goods',$newgoods);
		}
		return $newgoods;
	}
	function get_categorys() {
		global $_G;
		$categorys = $_G['cache']->get('index_categorys') ;
		if(!$categorys) {
			$query = $_G['db']->query("SELECT * FROM ".DB_PREFIX."product_category WHERE status=1 ");
			while($data = $_G['db']->fetch_array($query)){
				$category[$data['parentid']][$data['catid']] = $data;
			}
			$categorys = tree($category);
			$_G['cache']->set('index_categorys',$categorys);
		}
		return $categorys;
	}
}